package com.monitor.core.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.monitor.core.bean.ControllerMonitorMessage;
import com.monitor.core.bean.MonitorMessage;
import com.monitor.core.bean.ServiceMonitorMessage;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;

import java.io.UnsupportedEncodingException;

/**
 * @Auther: hanhui.liu
 * @Date: 2018/4/26 10:23
 * @Description:
 */
public class MessageUtil {

    public static ControllerMonitorMessage convert2ControllerMonitorMessage(Message message) throws UnsupportedEncodingException {
        String x = new String(message.getBody(), "utf-8");
        ControllerMonitorMessage cmm = JSON.parseObject(x, ControllerMonitorMessage.class);
        return cmm;
    }

    public static ServiceMonitorMessage convert2ServiceMonitorMessage(Message message) throws UnsupportedEncodingException {
        String x = new String(message.getBody(), "utf-8");
        ServiceMonitorMessage smm = JSON.parseObject(x, ServiceMonitorMessage.class);
        return smm;
    }
}
